package com.lcm.oj.tme.one;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author Coder-lcm
 * @date 2021/5/14
 */

public class ThreadTest{
    public static void main(String[] args) {
        ThreadDemo demo = new ThreadDemo(100);
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        for (int i = 0; i < 100; i++) {
            executorService.execute(() -> {
                demo.desc();
            });
        }

    }
}

class ThreadDemo {
    private ReentrantLock lock = new ReentrantLock(true);
    private Condition condition = lock.newCondition();
    private int count;

    public ThreadDemo(int count) {
        this.count = count;
    }

    public void desc(){
        lock.lock();
        try {
            System.out.println("isLock?" + lock.isLocked());
            System.out.println("wait count :" + lock.getWaitQueueLength(condition));
            System.out.println("queue length :" + lock.getQueueLength());
            System.out.println("is fair lock ? " + lock.isFair());
            System.out.println(count--);;
            System.out.println("hold lock times : " + lock.getHoldCount());
            System.out.println("______________________");

        }finally {
            lock.unlock();
        }
    }

    public void incr(){
        lock.lock();
        try {
            count++;
        }finally {
            lock.unlock();
        }
    }



}
